<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24' style='margin-left: 30%;margin-top: 5%;font-size: 30px'>
          <a-col :span='8' :xl='3'>
            <j-dict-select-tag style='width: 130px;' placeholder='请选择类型' v-model='queryParam.typeCode'
                               @change='searchQueryData' dictCode='controller_types_code' />
          </a-col>
          <a-col :span='8' :xl='8'>
            <a-input style='width: 360px' :placeholder='placeholder' @keypress='searchQueryData' v-model='queryParam.queryValues' />
          </a-col>
          <a-col :span='8'>
            <span>
              <a-button type='primary' style='width: 120px' @click='searchQueryData' icon="search">查询一下</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class='table-operator' style='margin-top: 40px'>
      <a-form layout='inline'>
        <stu-student-lable :studentVo='dataSourceStudentTotal'
                           :isStudentLableStatus='isStudentLableStatus'></stu-student-lable>
        <tea-teacher-lable :teacherVo='dataSourceTeacherTotal' :isTeacherLableStatus='isTeacherLableStatus'></tea-teacher-lable>
        <cou-class-lable :classVo='dataSourceClassTotal' :isClassLableStatus='isClassLableStatus'></cou-class-lable>
        <cou-grade-lable :isGradeLableStatus='isGradeLableStatus'></cou-grade-lable>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <stu-student-list-modal ref='refStuStudentListModal' :dataSourceModal='dataSourceTotalList'></stu-student-list-modal>
    <tea-teacher-list-modal ref='refTeaTeacherListModal' :dataSourceModal='dataSourceTotalList' ></tea-teacher-list-modal>
    <cou-class-list-modal ref='refCouClassListModal' :data-source-modal='dataSourceTotalList'></cou-class-list-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { getAction, postAction } from '@api/manage'
import JDate from '@/components/jeecg/JDate'
import StuStudentLable from './StuStudentLable'
import TeaTeacherLable from '@views/smart_school/smartSchoolController/TeaTeacherLable'
import CouClassLable from '@views/smart_school/smartSchoolController/CouClassLable'
import CouGradeLable from '@views/smart_school/smartSchoolController/CouGradeLable'
import StuStudentListModal from '@views/smart_school/student/StuStudentListModal'
import TeaTeacherListModal from '@views/smart_school/teacher/TeaTeacherListModal'
import CouClassListModal from '@views/smart_school/classes/CouClassListModal'

export default {
  name: 'SmartSchoolController',
  components: { JDate, StuStudentLable, TeaTeacherLable, CouClassLable, CouGradeLable, StuStudentListModal,TeaTeacherListModal,CouClassListModal },
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      disableMixinCreated : true, //默认初始状态不加载数据
      // 表头
      url: {
        queryStudentList: '/student/stuStudent/list',
        queryTeacherList: "/teacher/teaTeacher/list",
        queryClasslist: '/classes/couClass/list',
      },
      isStudentLableStatus: false,
      isTeacherLableStatus: false,
      isClassLableStatus: false,
      isGradeLableStatus: false,
      placeholder: '',
      dataSourceTotalList: [],
      dataSourceStudentTotal: {},
      dataSourceTeacherTotal: {},
      dataSourceClassTotal: {},
      pageNoSize: 1,
      pageSizeCount: 100
    }
  },
  created() {
    this.$bus.$on('closeStuStudentListModal', (val) => {
      console.log('closeStuStudentListModal监听总线返回了选择的数据了，你可以去操作其他页面',val)
      if (JSON.stringify(val) != "{}") {
        this.dataSourceStudentTotal = val
        this.queryParam.queryValues = this.dataSourceStudentTotal.studentName;
        this.isStudentLableStatus = true
      }else {
        this.dataSourceStudentTotal = {}
        this.isStudentLableStatus = false
      }
    })
    this.$bus.$on('closeTeaTeacherListModal', (val) => {
      console.log('closeTeaTeacherListModal监听总线返回了选择的数据了，你可以去操作其他页面',val)
      if (JSON.stringify(val) != "{}") {
        this.dataSourceTeacherTotal = val
        this.queryParam.queryValues = this.dataSourceTeacherTotal.teacherName;
        this.isTeacherLableStatus = true
      }else {
        this.dataSourceTeacherTotal = {}
        this.isTeacherLableStatus = false
      }
    })
    this.$bus.$on('closeCouClassListModal', (val) => {
      console.log('closeTeaTeacherListModal监听总线返回了选择的数据了，你可以去操作其他页面',val)
      if (JSON.stringify(val) != "{}") {
        this.dataSourceClassTotal = val
        this.queryParam.queryValues = this.dataSourceClassTotal.className;
        this.isClassLableStatus = true
      }else {
        this.dataSourceClassTotal = {}
        this.isClassLableStatus = false
      }
    })
  },
  computed: {},
  methods: {
    loadData() {
    },
    searchQueryData() {
      this.isStudentLableStatus = false
      this.isTeacherLableStatus = false
      this.isClassLableStatus = false
      this.isGradeLableStatus = false

      if (this.queryParam.typeCode == 'student') {
        this.placeholder = '请使用学号、姓名、身份证、一卡通、联系电话查询'
        if (this.queryParam.queryValues) {
          let params = {
            queryValues: this.queryParam.queryValues,
            pageNo: this.pageNoSize,
            pageSize: this.pageSizeCount
          }
          getAction(this.url.queryStudentList, params).then((res) => {
            if (res.success) {
              if (res.result.records.length > 0) {
                if (res.result.records.length > 1) {
                  this.dataSourceTotalList = res.result.records
                  this.$refs.refStuStudentListModal.openModal();
                } else {
                  this.dataSourceTotal = res.result.records[0]
                  this.isStudentLableStatus = true
                }

              } else {
                this.dataSourceTotal = {}
              }

            } else {
              this.$message.error(res.message)
            }
          })
        }
      }
      if (this.queryParam.typeCode == 'teacher') {
        this.placeholder = '请使用教职工号、姓名、身份证、联系电话查询'
        if (this.queryParam.queryValues) {
          let params = {
            queryValues: this.queryParam.queryValues,
            pageNo: this.pageNoSize,
            pageSize: this.pageSizeCount
          }
          getAction(this.url.queryTeacherList, params).then((res) => {
            if (res.success) {
              if (res.result.records.length > 0) {
                if (res.result.records.length > 1) {
                  this.dataSourceTotalList = res.result.records
                  this.$refs.refTeaTeacherListModal.openModal();
                } else {
                  this.dataSourceTotal = res.result.records[0]
                  this.isTeacherLableStatus = true
                }

              } else {
                this.dataSourceTotal = {}
              }

            } else {
              this.$message.error(res.message)
            }
          })
        }
      }
      if (this.queryParam.typeCode == 'class') {
        this.placeholder = '请使用编码、名称、简称查询'
        if (this.queryParam.queryValues) {
          let params = {
            queryValues: this.queryParam.queryValues,
            pageNo: this.pageNoSize,
            pageSize: this.pageSizeCount
          }
          getAction(this.url.queryClasslist, params).then((res) => {
            if (res.success) {
              if (res.result.records.length > 0) {
                if (res.result.records.length > 1) {
                  this.dataSourceTotalList = res.result.records
                  this.$refs.refCouClassListModal.openModal();
                } else {
                  this.dataSourceTotal = res.result.records[0]
                  this.isClassLableStatus = true
                }
              } else {
                this.dataSourceTotal = {}
              }

            } else {
              this.$message.error(res.message)
            }
          })
        }
      }
      if (this.queryParam.typeCode == 'grade') {
        this.isGradeLableStatus = true
      }
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';

.selected {
  /* 去掉三角 */
  appearance: none;
  -moz-appearance: none; /* Firefox */
  -webkit-appearance: none; /* Safari 和 Chrome */
  /* 去掉边框 */
  border: 0;
  display: block;
  position: relative;
}
</style>